package main

import (
	"master_go/event_bus/eventbus"
	"time"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	eBus := eventbus.NewEventBus()
	r.GET("/prods", func(c *gin.Context) {
		ch := eBus.Sub("prods")
		go func() { eBus.Pub("prods", GetList()) }()
		c.JSON(200, ch.Data(time.Second*1))
	})

	r.Run(":80")
}

func GetList() interface{} {
	time.Sleep(time.Second * 4)
	return gin.H{"message": []int{1, 2, 3}}
}
